package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by wqewqe on 2017/12/18.
 */

public  abstract  class CommonRecyclerAdapter<T> extends RecyclerView.Adapter<ViewHolder> {
    protected Context mContext;
    protected LayoutInflater mInflater;
    protected List<T> mDatas;
    protected int mLayoutId;

    public CommonRecyclerAdapter(Context mContext,List<T> mDatas, int mLayoutId) {
        this.mContext = mContext;
        this.mInflater=LayoutInflater.from(mContext);
        this.mDatas = mDatas;
        this.mLayoutId = mLayoutId;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(mLayoutId,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        convert(holder,mDatas.get(position));
    }
    public abstract void convert(ViewHolder holder,T items);
    @Override
    public int getItemCount() {
        return mDatas.size();
    }
}
